package com.kaikai.aclservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kaikai.aclservice.entity.AclPermission;
import com.kaikai.aclservice.service.AclPermissionService;
import com.kaikai.commonutils.R;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 权限 前端控制器
 * </p>
 *
 * @author yujiankai
 * @since 2021-07-10
 */
@CrossOrigin
@RestController
@RequestMapping("/aclservice/acl-permission")
public class AclPermissionController {

    @Autowired
    private AclPermissionService permissionService;

    @ApiModelProperty(value = "查询全部菜单数据")
    @GetMapping("indexAllPermission")
    public R indexAllPermission(){
        QueryWrapper<AclPermission> wrapper=new QueryWrapper<>();
        wrapper.orderByDesc("id");
        //获得全部数据
        List<AclPermission> PermissionList = permissionService.list(wrapper);
        //获取封装后所有数据
        List<AclPermission> result=permissionService.selectList(PermissionList);
        return R.ok().data("result",result);
    }

    @ApiModelProperty(value = "递归删除菜单")
    @GetMapping("remove/{id}")
    public R remove(@PathVariable String id){
//        permissionService.removeChildrenById(id);
        permissionService.deleteById(id);
        return R.ok();
    }
    @ApiModelProperty(value = "给角色添加权限")
    @PostMapping("/doAssign")
    public R doAssign(String roleId,String[] permissionIds){
        permissionService.saveRolePermissionRealtionShip(roleId,permissionIds);
        return R.ok();
    }

}

